﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
namespace QXJ
{
    public partial class DayData : UserControl
    {

        enum TABLESEQ
        {
            ID =0,
            quzhanhao =1,
            WeiDu = 2,
            JingDu = 3,
            HightOfGuanCheChang = 4,
            HightOfQIYaChuanGaiqi = 5,
            TypeOfGuanChe =6,
            Time = 7,//放在0上。
            TwoFZFXX =8,
            TwoFX =9,
            TenFx=10,
            TenFSpeed=11,
            MaxFXinag=12,
            MaxFSpeed=13,
            TimeOfMaxF=14,
            SunSiFXiang=15,
            SunSiFSpeed=16,
            JiDaFXiang=17,
            JiDaFSpeed=18,
            TimeOfJiDaF=19,
            RainVolPerHour=20,
            TempOfGanQiu=21,
            MaxWenDu=22,
            TimeOfMaxCuXian=23,
            MinWenDu=24,
            TimeOfMinWenDuChuXian=25,
            XiangDuShiDu=26,
            MinXiangDuShiDu=27,
            TimeOfMinShiDuChuXian=28,
            BenZhanQiYa=29,
            MaxOfBenZhan=30,
            TimeOfMaxOfBenZhan=31,
            LowestOfOur=32,
            TimeOfLowest=33,
            VolOfRainOneHour=34,
            IDONKNOW
        }
        public DayData()
        {
            InitializeComponent();
            this.dataGridView1.BackgroundColor = Color.White;
            
        }
        private string _quzhanhao;
        //区站号
        public string QuZhanHao
        {
            get { return _quzhanhao; }
            set { _quzhanhao = value; }
        }
        private DateTime _dt;
        //日期
        public DateTime Dt
        {
            get { return _dt; }
            set { _dt = value; }
        }
        //DG
        public DataGridView dgv
        {
            get { return this.dataGridView1; }
        }

        /// <summary>
        /// Load ，只在加载的时候，调用 一次。以后就不会再调用 了
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DayData_Load(object sender, EventArgs e)
        {
            ShowRianMinute();
            SetRainData();
            DataGridViewTextBoxColumn[] dgvtbc = new DataGridViewTextBoxColumn[33];
            for (int i = 0; i < 33; i++)
            {
                dgvtbc[i] = new DataGridViewTextBoxColumn();
                this.dataGridView2.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            dgvtbc[i]});
            }
            dgvtbc[0].HeaderText = "时间";
            
            //this.dataGridView1.Columns
            if (!string.IsNullOrEmpty(QuZhanHao) && Dt != null)
            {
               

            }
            else
            {
                //DBUtility.DataAccess.GetDataTable();
            }
        }
        /// <summary>
        /// 设置显示雨量的
        /// </summary>
        private void ShowRianMinute()
        {
            this.dataGridView2.TopLeftHeaderCell.ToolTipText = "显示一小时时间内，每分钟对应的雨量";
            this.dataGridView2.TopLeftHeaderCell.Value = "时间";
            DataGridViewTextBoxColumn[] dgvtbc = new DataGridViewTextBoxColumn[30];
            for (int i = 0; i < 30; i++)
            {
                dgvtbc[i] = new DataGridViewTextBoxColumn();
                dgvtbc[i].HeaderText = i.ToString() + "(" + (i + 30).ToString() + ")";
                this.dataGridView2.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            dgvtbc[i]});
                dgvtbc[i].ToolTipText = "当前时间：第" + i.ToString() + "分钟(第" + (i + 30).ToString() + "分钟)";
            }
        }

        /// <summary>
        /// 把雨量数据传递进来。长度应该是120位
        /// </summary>
        /// <param name="str"></param>
        private void SetRainData(string str = "")
        {

            //str = "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111";
            for (int i = 0; i < 30; i++)
            {
                if (string.IsNullOrEmpty(str))
                {
                    this.dataGridView2.Rows[0].Cells[i].Value = "00(00)";//默认值为00
                }
                else
                {
                    try
                    {
                        this.dataGridView2.Rows[0].Cells[i].Value = str.Substring(i * 2, 2) + "(" + str.Substring(i * 2 + 60, 2) + ")";
                    }
                    catch//无值的时候，为00
                    {
                        this.dataGridView2.Rows[0].Cells[i].Value = "00(00)";//默认值为00
                    }
                }
            }

        }

        public void SetDateQZH(DateTime dt,string qzh)
        {
            QuZhanHao = qzh;
            Dt = dt;
        }
        public void UpdateShow()
        {
            //show
            DataTable dt = DBUtility.DataAccess.GetDataTable("select * from qxj where `quzhanhao`= 'I1353'");
          //  OutDataTable(dt);
            if (dt == null || dt.Rows.Count < 1)
            {
                MessageBox.Show(" 没有查询到数据 ");
                return;
            }
            else
            {
                
            }
            
        }
        //for test
        void OutDataTable(DataTable dt)
        {
            for (var i = 0; i < dt.Rows.Count; i++)
            {
                for (var j = 0; j < dt.Columns.Count; j++)
                {
                    Console.Write(dt.Rows[i][j]);
                    Console.Write("   |   ");
                }
                Console.WriteLine();
            }
        }
    }
}
